<template>
  <BaseLayout>
    <template v-slot:main-left>
      <Institution />
    </template>
    <template v-slot:main-button>
      <mainButton
        @toMainSearch="search"
        @toMainSearchReset="reset"
        :main-button="mainButton"
      />
    </template>
    <template v-slot:search-info>
      <searchMain
        size="mini"
        :label-width="labelWidth"
        ref="searchMain"
        :model="formData"
        :rules="searchRules"
        :itemList="formItemList"
      />
      <el-divider />
    </template>
    <template v-slot:table-main>
      <common-table
        :data="infoList"
        border
        :columns-item="columns"
        :title="infoTitle"
        :loading="false"
        :item-list="itemList"
        :displayColumn="displayColumn"
        @checkbox-change="selectChangeEvent"
      />
    </template>
    <template v-slot:table-member>
      <common-table
        :data="testList"
        border
        :columns-item="testColumns"
        :title="testTitle"
        @checkbox-change="selectChangeEvent"
      />
    </template>
  </BaseLayout>

  <!-- <health-info :dialog-visible.sync="dialogVisible" /> -->
</template>

<script>
import BaseLayout from "@/components/Layout/base.vue"
import Institution from "@/components/Trees/Institution.vue"
import mainButton from "@/components/CommonButtons/MainButton.vue"
import searchMain from "@/components/CommonForm/index.vue"
import CommonTable from "@/components/CommonTable/index.vue"
// 加载模拟数据
import {
  infoList,
  testList,
  sexs,
  fileStatusType,
  liveType,
  dataSource,
  helpPoor,
  peopleSigns,
  publicSigns,
  addressList,
  information,
  checkType,
  diseaseType,
  examineType,
  searchTime,
  year,
  dataProps,
  searchHandle
} from "@/simdata/healthData.js"
export default {
  components: {
    BaseLayout,
    Institution,
    mainButton,
    searchMain,
    CommonTable
  },
  // directives: { resizeSpan },
  data() {
    return {
      // 配置标题显示图标颜色
      itemList: [
        {
          label: "高",
          color: "#66FFFF"
        },
        {
          label: "糖",
          color: "#f3daf9"
        },
        {
          label: "精",
          color: "#FFCC99"
        },
        {
          label: "贫",
          color: "#BF924C"
        },
        {
          label: "新",
          color: "#3D9F54"
        },
        {
          label: "结",
          color: "#87FE03"
        }
      ],
      // 配置常用按钮
      mainButton: [
        {
          label: "新增",
          icon: "el-icon-circle-plus-outline",
          type: "primary",
          handle: () => this.addHandle()
        },
        {
          label: "导出Excel",
          icon: "el-icon-edit-outline",
          type: "success",
          handle: () => {
            console.log("点击了")
          }
        }
      ],
      // 查询表单
      formData: {
        keyword: "", // 个人信息项 字段
        keyValue: "", // 值
        ageStart: "", // 年龄开始
        ageEnd: "", // 年龄结束
        isCheck: null, // 是否体检
        disease: null, // 慢病人群分类
        examine: null, // 审核状态
        searchTime: null, // 时间查询项目
        yearData: null, // 年度
        createDate: null, // 建档日期 开始
        endDate: null // 结束日期
      },
      // label的宽度
      labelWidth: "auto",
      // 验证
      searchRules: {
        isCheck: [
          { required: true, message: "请选择是否体检", trigger: "change" }
        ],
        searchTime: [
          { required: true, message: "请选择时间查询项目", trigger: "change" }
        ]
      },
      // 配置search label表单
      formItemList: [
        {
          type: "Select",
          label: "个人信息查询项目", // 个人信息查询项目
          prop: "keyword",
          width: "120px",
          span: 8,
          options: information,
          props: dataProps,
          change: row => "",
          placeholder: "请选择..."
        },
        {
          type: "Input",
          label: "",
          prop: "keyValue",
          width: "120px",
          span: 8,
          placeholder: ""
        },
        {
          type: "Input",
          label: "年龄段",
          prop: "ageStart",
          span: 5,
          placeholder: ""
        },
        {
          type: "Input",
          label: "",
          prop: "ageEnd",
          span: 2,
          placeholder: ""
        },
        {
          type: "Select",
          label: "是否体检",
          prop: "isCheck",
          width: "120px",
          span: 8,
          options: checkType,
          props: dataProps,
          change: row => "",
          placeholder: "请选择..."
        },
        {
          type: "Select",
          label: "慢病人群分类",
          prop: "disease",
          width: "120px",
          span: 8,
          options: diseaseType,
          props: dataProps,
          change: row => "",
          placeholder: "请选择..."
        },
        {
          type: "Select",
          label: "审核状态",
          prop: "examine",
          width: "120px",
          span: 8,
          options: examineType,
          props: dataProps,
          change: row => "",
          placeholder: "请选择..."
        },
        {
          type: "Select",
          label: "时间查询项目",
          prop: "searchTime",
          width: "120px",
          span: 6,
          options: searchTime,
          props: dataProps,
          change: row => "",
          placeholder: "请选择..."
        },
        {
          type: "Select",
          label: "",
          prop: "yearData",
          width: "120px",
          span: 4,
          options: year,
          props: dataProps,
          change: row => "",
          placeholder: "请选择..."
        },
        {
          type: "data",
          label: "建档日期",
          prop: "createDate",
          width: "140px",
          span: 6,
          placeholder: "请选择..."
        },
        {
          type: "data",
          label: "至",
          prop: "endDate",
          width: "140px",
          span: 6,
          placeholder: "请选择..."
        }
      ],
      // 所有列表数据
      infoTitle: "人员基本信息列表",
      testTitle: "人员体检信息列表",
      infoList: infoList,
      testList: testList,
      // 配置显示的label标签
      columns: [
        { prop: "name", label: "姓名", width: "100" },
        {
          prop: "sex",
          label: "性别",
          width: "68",
          type: "sex",
          option: sexs
        },
        { prop: "age", label: "年龄", width: "80" },
        { prop: "birthdata", label: "出生日期", width: "100" },
        { prop: "identityNumber", label: "身份证号", width: "180" },
        { prop: "phonenumber", label: "本人电话号码", width: "150" },
        { prop: "linkName", label: "联系人姓名", width: "100" },
        { prop: "linkNumber", label: "联系人电话", width: "150" },
        { prop: "nowAddress", label: "现住地址", width: "150" },
        {
          prop: "isSign",
          label: "是否签约",
          width: "80",
          type: "isSign",
          callback: row => {
            let text = ""
            switch (row.isSign) {
              case 1:
                text = "已签约"
                break
              case 2:
                text = "未签约"
                break
              default:
                text = "其他"
            }
            return text
          }
        }, //
        { prop: "responsibleDoctor", label: "责任医生", width: "100" },
        {
          prop: "isHome",
          label: "家庭信息",
          width: "80",
          type: "isHome",
          callback: row => {
            let text = ""
            switch (row.isHome) {
              case 1:
                text = "有"
                break
              case 2:
                text = "无"
                break
              default:
                text = "其他"
            }
            return text
          }
        }, //
        { prop: "creatDoctor", label: "建档医生", width: "100" },
        { prop: "createDate", label: "建档日期", width: "100" },
        { prop: "myNumber", label: "个人健康档案号", width: "150" },
        { prop: "number", label: "家庭档案号", width: "150" },
        {
          prop: "isComplete",
          label: "信息是否完整",
          width: "120",
          type: "isComplete",
          callback: row => {
            let text = ""
            switch (row.isComplete) {
              case 1:
                text = "完整"
                break
              case 2:
                text = "不完整"
                break
              default:
                text = "其他"
            }
            return text
          }
        },
        {
          prop: "isLibrary",
          label: "人口库标记",
          width: "100",
          type: "isLibrary",
          callback: row => {
            let text = ""
            switch (row.isLibrary) {
              case 1:
                text = "是"
                break
              case 2:
                text = "否"
                break
              default:
                text = "其他"
            }
            return text
          }
        },
        {
          prop: "isPublic",
          label: "公安标记",
          width: "80",
          type: "isPublic",
          callback: row => {
            let text = ""
            switch (row.isPublic) {
              case 1:
                text = "是"
                break
              case 2:
                text = "否"
                break
              default:
                text = "其他"
            }
            return text
          }
        }
      ],
      // 控制表格操作按钮的显示隐藏
      displayColumn: {
        operationCol: true,
        editBtn: true,
        removeBtn: true
      },
      // test配置label标签
      testColumns: [
        { prop: "name", label: "姓名", width: "100" },
        { prop: "sex", label: "性别", width: "68" },
        { prop: "age", label: "年龄", width: "80" },
        { prop: "birthdata", label: "出生日期", width: "100" },
        { prop: "identityNumber", label: "身份证号", width: "180" },
        { prop: "relation", label: "与户主关系", width: "100" }
      ]
    }
  },
  methods: {
    // 点击新增按钮
    addHandle() {
      console.log("点击新增了")
    },
    // 切换常用地址
    handleChange() {
      console.log("点击了")
    },
    // 点击搜索按钮
    search(formName) {
      this.$refs.searchMain.$refs[formName].validate(valid => {
        if (valid) {
          console.log(this.formData)

          // 调用接口
          this.callbackComponent()
        } else {
          console.log("error submit!!")
          return false
        }
      })
    },
    // 点击重置按钮
    reset(formName) {
      this.$refs.searchMain.$refs[formName].resetFields()
      // console.log(this.formData)
    },
    // 点击搜索后，请求后台接口了
    callbackComponent() {
      console.log("调接口")
    },
    // 家庭基本信息复选框选中
    selectChangeEvent({ checked, records }) {
      console.log(checked)
      console.log(records)
    }
  }
}
</script>

<style lang="scss" scoped></style>
